<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Data extends Model
{
    protected $table = 'datas';

    protected $fillable = [
        'type','user_id','title','file','coins','filesize','image','images','appversion','renderertype','cat_id1','cat_id2','style','is_light','status','collecnum','viewnum','downnum','is_del','images_thumb','note','published_at'
    ];

    public function getIslightAttribute($value)
    {
        return $value?'有':'无';
    }

    public function getImagesAttribute($value)
    {
        return explode(',',$value);
    }
    public function getImagesthumbAttribute($value)
    {
        return explode(',',$value);
    }
    public function user()
    {
        return $this->belongsTo('App\User');
    }
    public function catid1(){
        return $this->hasOne('App\Cat','id','cat_id1');
    }
    public function catid2(){
        return $this->hasOne('App\Cat','id','cat_id2');
    }
    public function cstyle(){
        return $this->hasOne('App\Cat','id','style');
    }

    /**
     * 获得此用户收藏的所有模型。
     */
    public function data()
    {
        return $this->morphMany('App\Collect', 'commentable');
    }

}
